package com.yunhe.exaple.servlet;

import com.yunhe.exaple.dao.StudentDao;
import com.yunhe.exaple.entity.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/")
public class StudentServlet extends HttpServlet {
    private StudentDao studentDao = new StudentDao();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String page = req.getParameter("page");
        String pageSize = req.getParameter("pageSize");
        page = null == page ? "1" : page;
        pageSize = null == pageSize ? "10" : pageSize;
        List<Student> stuList = studentDao.findForPage(Integer.parseInt(page), Integer.parseInt(pageSize));
        req.setAttribute("stuList",stuList);
        req.getRequestDispatcher("/WEB-INF/index.jsp").forward(req,resp);
    }
}
